    //
//  MainMenuViewController.m
//  _2010WorldCupNationalAthem
//
//  Created by Apple on 2010/7/11.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "MainMenuViewController.h"
#import "CountryTableViewController.h"


@implementation MainMenuViewController


@synthesize listData ;



//**********************************************************
// Privtate method:  jump2CountryTableView
// 跳到國家列表
//**********************************************************
//
-(void) jump2CountryTableView:(NSUInteger)row 
{	
	CountryTableViewController * tempCountryTableView ;

	selectedRow = row ;
	
	//allocate a temp. country-table-view
	tempCountryTableView = [[CountryTableViewController alloc]initWithNibName:@"CountryTableView" bundle:nil];
	
	[tempCountryTableView setTableSelection:row] ;
	
	[self.navigationController pushViewController:tempCountryTableView animated:YES] ;
	
	[tempCountryTableView release] ;
	
}





//**********************************************************
// Privtate method:  touchButtonToCountryTable
//
//**********************************************************

-(IBAction)touchButtonToCountryTable:(id)sender
{
	[self jump2CountryTableView:0] ;	
	
}


//**********************************************************
// org. method:  viewDidLoad
//Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
//**********************************************************
- (void)viewDidLoad
{
	NSArray * array = [[NSArray alloc] initWithObjects:
					   @"Group A-H",
					   @"Round of 16",
					   @"Quarter-Finals",
					   @"Semi-Finals",
					   @"Final",
					   @"Champions",
					   nil] ;
	
	CGRect rect = CGRectMake(0, 0, 200, 44);
	UILabel * nav_bar_title ;
	
		
	//*** copy-code start: 設定navigation bar的title
	//
	nav_bar_title = [[UILabel alloc] initWithFrame:rect];
    nav_bar_title.backgroundColor = [UIColor clearColor];
    nav_bar_title.text = @"   Matchs";
    
	
    self.navigationItem.titleView = nav_bar_title;
	//
	//*** copy-code end

	self.listData = array ;

	[array release] ;
	[super viewDidLoad] ;
}





/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload 
{
    [super viewDidUnload];
	
	self.listData = nil ; 
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc 
{
	[listData release] ;
    
	[super dealloc];
}


#pragma mark -
#pragma mark Table View Data Source Methods


//**********************************************************
// org. method:  tableView:numberOfRowsInSection
//
//**********************************************************

- (NSInteger) tableView:(UITableView *)tableView
				numberOfRowsInSection: (NSInteger) section
{
	return [self.listData count] ;
}


//**********************************************************
// org. method:  tableView:cellForRowAtIndexPath
//
//**********************************************************

- (UITableViewCell *)tableView:(UITableView *)tableView
					cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
	static NSString * SimpleTableIdentifier = @"SimpleTableIdentifier" ;
	
	UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier] ;
	
	if(cell == nil)
	{
		cell = [[[UITableViewCell alloc]
				 initWithStyle:UITableViewCellStyleDefault 
				 reuseIdentifier:SimpleTableIdentifier] autorelease] ;
	}
	
	NSUInteger row = [indexPath row] ;
	cell.textLabel.text = [listData objectAtIndex:row] ;
	
	return cell ;
}


#pragma mark -
#pragma mark Table View Delegate Methods

- (void)tableView: (UITableView *)tableView
didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
	selectedRow = [indexPath row] ;
	[self jump2CountryTableView:selectedRow] ;

}

@end
